<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
    <title>ShellCheck: SC3003 – In POSIX sh, `$'..'` is undefined.</title>
    <link rel="stylesheet" href="css/bootstrap.min.css" />
  </head>
  <body style="margin-left: auto; margin-right: auto; max-width: 800px">
    <h1>SC3003 – ShellCheck Wiki</h1>
    <a href="https://github.com/koalaman/shellcheck/wiki/SC3003">See this page on GitHub</a>
    <p style="display: none"><a href="index.html">Sitemap</a></p>
    <hr />
    <h2 id="in-posix-sh--is-undefined">In POSIX sh, <code>$'..'</code> is
undefined.</h2>
<h3 id="problematic-code">Problematic code:</h3>
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="SC3003.html#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="co">#!/bin/sh</span></span>
<span id="cb1-2"><a href="SC3003.html#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="va">IFS</span><span class="op">=</span><span class="st">$&#39; </span><span class="dt">\t\n</span><span class="st">&#39;</span></span></code></pre></div>
<h3 id="correct-code">Correct code:</h3>
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="SC3003.html#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="co">#!/bin/sh</span></span>
<span id="cb2-2"><a href="SC3003.html#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="co"># Note: \n can not be last, or it will be stripped by $()</span></span>
<span id="cb2-3"><a href="SC3003.html#cb2-3" aria-hidden="true" tabindex="-1"></a><span class="va">IFS</span><span class="op">=</span><span class="va">$(</span><span class="bu">printf</span> <span class="st">&#39; \n\t&#39;</span><span class="va">)</span></span></code></pre></div>
<p>or</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="SC3003.html#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="co">#!/bin/sh</span></span>
<span id="cb3-2"><a href="SC3003.html#cb3-2" aria-hidden="true" tabindex="-1"></a><span class="co"># Trailing linefeed added literally</span></span>
<span id="cb3-3"><a href="SC3003.html#cb3-3" aria-hidden="true" tabindex="-1"></a><span class="va">IFS</span><span class="op">=</span><span class="st">&quot;</span><span class="va">$(</span><span class="bu">printf</span> <span class="st">&#39; \t&#39;</span><span class="va">)</span></span>
<span id="cb3-4"><a href="SC3003.html#cb3-4" aria-hidden="true" tabindex="-1"></a><span class="st">&quot;</span></span></code></pre></div>
<p>or</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="SC3003.html#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="co">#!/bin/bash</span></span>
<span id="cb4-2"><a href="SC3003.html#cb4-2" aria-hidden="true" tabindex="-1"></a><span class="co"># Bash supports this</span></span>
<span id="cb4-3"><a href="SC3003.html#cb4-3" aria-hidden="true" tabindex="-1"></a><span class="va">IFS</span><span class="op">=</span><span class="st">$&#39; </span><span class="dt">\t\n</span><span class="st">&#39;</span></span></code></pre></div>
<h3 id="rationale">Rationale:</h3>
<p>ANSI-C quoting, <code>$'..'</code>, is a <code>bash</code> extension,
which is not supported by POSIX <code>sh</code>.</p>
<p>To ensure the script runs correctly on other systems, either switch
to Bash, or rewrite it in a POSIX compatible way.</p>
<p>This can generally done via <code>printf</code> as in the example. Be
careful about strings with trailing linefeeds, as a
<code>$(command substitution)</code> will strip them.</p>
<h3 id="exceptions">Exceptions:</h3>
<p>None.</p>
<h3 id="related-resources">Related resources:</h3>
<ul>
<li>StackOverflow: <a
href="https://stackoverflow.com/questions/15179446/why-does-my-bash-code-fail-when-i-run-it-with-sh">Why
does my bash code fail when I run it with sh?</a></li>
</ul>
    <hr />
    <p style='font-size: 80%'><a href="../index.html">ShellCheck</a> is a static analysis tool for shell scripts. This page is part of its documentation.</p>
  </body>
</html>


